package edu.sctu.alex.projectPratice.subwaySystem2.dataUntil;

import edu.sctu.alex.projectPratice.subwaySystem2.MetroStation.*;
import edu.sctu.alex.projectPratice.subwaySystem2.Passenger;

import java.util.HashMap;

/**
 * Created by user03 on 2015/6/9.
 */
public class PassengerUtil {

    InfoSet infoSet = new InfoSet();

    Passenger[] passengers = infoSet.setPassenger();
    MonitorMachine monitorMachine = new MonitorMachine();


    public void actAllAction() {
        buyCard();
        abnormalAction();
        monitorMachine.checkPackage();
        monitorMachine.checkWater();
        onMetro();
        useTime();
        consume();

    }

    public void buyCard() {


        if (passengers[0].getCard().getBalance() <= 2) {

            System.out.println("余额不足，请买票！");

        } else {

            System.out.println("余额充足，请刷卡请通行！");
        }


    }

    /**
     * 判断是否有小偷行为
     */
    public void abnormalAction() {
        MonitorPerson monitorPerson = new MonitorPerson();
        if (monitorPerson.warningPassenger()) {

            System.out.println("地铁站出现危险人物");

        } else {
            System.out.println("环境安全，请放心出行！");

        }

    }

    /**
     * 乘坐地铁的过程中，地铁出现突发状况的处理 方法
     */

    public void onMetro() {
        MonitorProblem monitorProblem = new MonitorProblem();

        boolean p = monitorProblem.checkProblem("平静");

        if (p) {

            System.out.println("列车运行出现问题，请相关部门出动！");
        } else {

            System.out.println("列车运行正常！");
        }

    }

    /**
     * 列车运行的时间处理方法
     */
    public void useTime() {

        MetroStation metroStation = new MetroStation();
        HashMap<String, Integer> map;
        map = metroStation.setHashMapData();

        int stationNumber;

        stationNumber = (map.get(passengers[0].getRoute().getEndStation())) -

                (map.get(passengers[0].getRoute().getStartStation()));

        if (stationNumber < 0) {
            stationNumber = -stationNumber;
        }
        MonitorSystem monitorSystem = new MonitorSystem();
        monitorSystem.alarm(stationNumber);
    }

    /**
     * 地铁计费规则
     * 扣款规则，3站以内2元，6站以内4元，8站以内5元。超过8站以上6元。
     */
    public void consume() {
        MetroStation metroStation = new MetroStation();
        HashMap<String, Integer> map;
        map = metroStation.setHashMapData();

        int count = 0;//乘车需要支付的钱
        int stationNumber;


        stationNumber = (map.get(passengers[0].getRoute().getEndStation())) -

                (map.get(passengers[0].getRoute().getStartStation()));

        if (stationNumber >= 0) {
            System.out.println("乘坐站数：" + stationNumber);

        } else {
            stationNumber = -stationNumber;
            System.out.println("乘坐站数：" + stationNumber);
        }

        if (stationNumber >= 0 && stationNumber <= 3) {
            count = 2;

        } else if (stationNumber >= 4 && stationNumber <= 6) {

            count = 4;
        } else if (stationNumber >= 7 && stationNumber <= 8) {

            count = 5;

        } else if (stationNumber >= 9) {

            count = 6;
        }


        passengers[0].getCard().setBalance((passengers[0].getCard().getBalance()) - count);

        System.out.println("本次乘坐，起点站：" + passengers[0].getRoute().getStartStation());
        System.out.println("本次乘坐，终点站：" + passengers[0].getRoute().getEndStation());
        System.out.println("费用：" + count);
        System.out.println("卡上余额：" + passengers[0].getCard().getBalance());

    }


}

